package cn.gson.springboot.model.service;


import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;

import cn.gson.springboot.model.dao.DepartmentsDAO;
import cn.gson.springboot.model.dao.UserDAO;
import cn.gson.springboot.model.mapper.UserMapper;
import cn.gson.springboot.model.pojos.DepartmentsPx;
import cn.gson.springboot.model.pojos.User;

@Service
@Transactional(rollbackFor=Exception.class)
public class Userservice {
	
	@Autowired
	private  UserDAO udao;
	
	@Autowired
	private  UserMapper umap;
	@Autowired
	private DepartmentsDAO dp;
	
	
	//根据用户id查询用户实体
	public User iduser(Integer userId) {
		return udao.iduser(userId);
	}
	//清除角色
	public User qcjs(Integer userId) {
		return umap.qcjs(userId);
	}
	
	
	//查询用户登录
	public User saveOrder(String userName,String userPwd) {
		User u=udao.cxyh(userName,userPwd);
		return u;
		}
	
	
	public List<Map<String,Object>> cxsy() {
		List<Map<String,Object>> ll= umap.cxsy(); 
		return ll;
	}
	
	public List<Map<String,Object>> mhcxyh(String a) {
		List<Map<String,Object>> ll= umap.mhcxyh(a); 
		return ll;
	}
	public User cxxq(int a) {
			return umap.cxxq(a);
	}
	public JSONArray cxxqa(int a) {
		JSONArray ll= umap.cxxqa(a);
		return ll;
}
	public User xgmm(int yhid,String pwd,String pwds) {
		User u=udao.mmcxyh(yhid,pwd);
		u.setUserPwd(pwds);
		return u;
		
	}
	public void xgxx(int user_id,String yhname,String phone,String zt,int xzksa) {
		System.out.println("id"+user_id);
		User u=udao.findById(user_id).get();
		System.out.println("我是："+u);
		u.setUserPhone(phone);
		u.setUserName(yhname);
		DepartmentsPx d= dp.findById(xzksa).get();
		u.setDepartmentsPx(d);
		System.out.println("状态是:["+zt+"]");
		/*String m="在职";*/
		if("在职".equals(zt.trim())) {
			System.out.println("我没有辞职");
			u.setIsdelete(1);
		}else{
			System.out.println("我辞职了");
			u.setIsdelete(0);
		}

		udao.save(u);
	}
	public void xzyh(String xzname,int xzage,String xzsex,String xzphone,String xzsfz,String xzzt,int xzkeshi) {
		System.out.println("name"+xzname);
		User u=new User();
		u.setUserName(xzname);
		u.setUserPhone(xzphone);
		u.setUserSex(xzsex);
		u.setUserSfz(xzsfz);
		u.setUserPwd("123456");
		
		DepartmentsPx d= dp.findById(xzkeshi).get();
		u.setDepartmentsPx(d);
		u.setUserDate(new Timestamp(new Date().getTime()));
		if("在职".equals(xzzt)) {
			u.setIsdelete(1);
		}else if(xzzt.equals("离职")){
			u.setIsdelete(0);
		}

		udao.save(u);
	}
	public User pccf(String xzsfz) {
		User u=udao.pdcf(xzsfz);
		return u;
	}
		//pddao.saveAll(details);

}
